package com.tjvib.view.fragment;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSnapHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.tjvib.R;
import com.tjvib.adapter.SensorAdapter;
import com.tjvib.base.BaseFragment;
import com.tjvib.bean.SensorBean;

import java.util.ArrayList;
import java.util.List;

public class SensorFragment extends BaseFragment {

    private RecyclerView frag_sen_rv;
    private SensorAdapter sensorAdapter;
    private List<SensorBean> sensorBeanList = new ArrayList<>();


    @Override
    protected int getContentView() {
        return R.layout.fragment_sensor;
    }

    @Override
    protected void initView() {
        frag_sen_rv = getView().findViewById(R.id.frag_sen_rv);
    }

    @Override
    protected void initData() {
        sensorBeanList = new ArrayList<>();
        SensorBean sensorBean1 = new SensorBean();
        sensorBean1.setCon("直接使用您的Android手机上配备的传感器");
        sensorBean1.setName("手机自带传感器");
        sensorBean1.setIs_buy(false);
        sensorBean1.setPic_url("https://pic.baike.soso.com/p/20130618/20130618122420-1032473124.jpg");

        SensorBean sensorBean2 = new SensorBean();
        sensorBean2.setCon("蓝牙连接更专业的LPMS-B2传感器");
        sensorBean2.setName("LPMS-B2传感器");
        sensorBean2.setIs_buy(true);
        sensorBean2.setPic_url("https://ts1.cn.mm.bing.net/th/id/R-C.dfbaf400df2b10560371f1658a79113f?rik=BJM4LZsAGqF%2bzg&riu=http%3a%2f%2fwww.ukelai.com%2fuploadfile%2f2016%2f0616%2f20160616101243802.jpg&ehk=Y3ag5C1KHXbH1smtPSuvk3dCxA52poG2PoRIpS7aQCw%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1");

        SensorBean sensorBean3 = new SensorBean();
        sensorBean3.setCon("蓝牙连接更专业的ZeroLab传感器");
        sensorBean3.setName("ZeroLab传感器");
        sensorBean3.setIs_buy(true);
        sensorBean3.setPic_url("https://www.zero-lab.tech/images/LOGO1.png");

        sensorBeanList.add(sensorBean1);
        sensorBeanList.add(sensorBean2);
        sensorBeanList.add(sensorBean3);

        sensorAdapter = new SensorAdapter(R.layout.item_sensor, sensorBeanList, getView().getContext());
        frag_sen_rv.setLayoutManager(new LinearLayoutManager(getView().getContext()));
        LinearSnapHelper snapHelper = new LinearSnapHelper();
        snapHelper.attachToRecyclerView(frag_sen_rv);
        frag_sen_rv.setAdapter(sensorAdapter);
    }
}